package learn.bean;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * TODO
 *
 * @author FengQing
 * @date 2023/2/11 16:56
 */

public class Person {

	private String name;
	private Integer age;

	/**  Bean 初始化之后实现相应的初始化逻辑
     *  refresh() -> finishBeanFactoryInitialization()【倒数第二方法】 -> DefaultListableBeanFactory#preInstantiateSingletons-> getBean() -> doCreateBean()
     * -> initializeBean() ->applyBeanPostProcessorsBeforeInitialization()->【BeanPostProcessor】InitDestroyAnnotationBeanPostProcessor#postProcessBeforeInitialization()
     * -> findLifecycleMetadata()【找到@PostConstruct的方法】-> method.invoke()->postConstruct()
     * **/
	@PostConstruct
	public void postConstruct(){
		System.out.println(this.getClass().getSimpleName()+":postConstruct()");
	}

	/** Bean 注销时完成一些清扫工作 **/
	@PreDestroy
	public void preDestroy(){
		System.out.println(this.getClass().getSimpleName()+":preDestroy()");
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	public Person(String name, Integer age) {
		super();
		this.name = name;
		this.age = age;
	}

	@Override
	public String toString() {
		return "Person [name=" + name + ", age=" + age + "]";
	}

}
